from django.contrib import admin

# Things needed from NoPBX
from nopbx.dialplan.models import Context, Extension
from nopbx.device.models import Line

#
#
#
class ContextAdmin(admin.ModelAdmin):
    list_display = ('name', 'context_type', 'description')

    fieldsets = [
        (None, {'fields': ['name', 'context_type', 'description']}),
    ]

admin.site.register(Context, ContextAdmin)




class DeviceLineInline(admin.TabularInline):
    model = Line
    extra = 0
    exclude = ('username', 'password')
    readonly_fields = ('device', 'index')
    verbose_name_plural = 'Lines to call'

    fieldsets = [
        (None, {'fields': ['device', 'index', 'caller_id']}),
    ]

class ExtensionAdmin(admin.ModelAdmin):
    list_display = ('extension', 'context', 'description')
    list_editable = ('description',)
    filter_horizontal = ('calendars',)

    fieldsets = [
        (None,        {'fields': ['context', 'extension', 'description']}),
        ('Calendars', {'fields': ['calendars'], 'classes': ['collapse']}),
    ]

    inlines = [DeviceLineInline]

admin.site.register(Extension, ExtensionAdmin)

